package com.example.sync.po;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import com.example.sync.constant.Constant;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;

import java.util.Date;

/**
 * @author chentao
 * @version 1.0
 * @description: TODO
 * @date 2025/3/22 下午12:27
 */
@Data
@TableName(value = "sys_async_job")
public class SysASyncJob extends Model<SysASyncJob> {

    //消息的id
    @TableId(type = IdType.AUTO)
    private Long id;

    //消息的类型
    @TableField(value = "type")
    private String type;

    //消息的内容
    @TableField(value = "target_content")
    private String targetContent;

    //消息模块
    @TableField(value = "target_model")
    private String targetModel;

    //消息消费的状态
    @TableField(value = "status")
    private int status = Constant.RUNNING;

    //处理节点
    @TableField(value = "server_id")
    private Long serverId;

    //重试次数
    @TableField(value = "retry_count")
    private int retryCount;

    //下次重试时间
    @TableField(value = "retry_time")
    private Date retryTime;

    //错误信息
    @TableField(value = "error_message")
    private String errorMessage;

    //模块业务id
    @TableField(value = "model_id")
    private Long modelId;

    //模块模块名称
    @TableField(value = "model_name")
    private String modelName;

    //模块模块key
    @TableField(value = "model_key")
    private String modelKey;

    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time")
    private Date createTime;

    //更新时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time")
    private Date updateTime;

    public void recalculateFields() {
        if (this.createTime == null) {
            this.createTime = new Date();
        }
        this.updateTime = new Date();
    }
}
